package com.mdlib.helper.ui.fragments.home;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.ljlib.core.base.BaseFragment;
import com.ljlib.help.R;
import com.mdlib.helper.ui.adapter.GenericViewPagerAdapter;
import com.mdlib.helper.ui.fragments.sect.my.SendHistoryOrderFragment;
import com.mdlib.helper.ui.fragments.sect.my.SendOngoingOrderFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：HQY on 16/11/22 17:13
 * 邮箱：hqy_xz@126.com
 */

public class SendMyOrdersFragment extends BaseFragment {

    @Bind(R.id.tv_generic_title)
    TextView mTvGenericTitle;
    @Bind(R.id.tab_meyorder_top)
    TabLayout mTabMeyorderTop;
    @Bind(R.id.vp_myorder_pager)
    ViewPager mVpMyorderPager;

    private SendHistoryOrderFragment sendHistoryOrderFragment;
    private SendOngoingOrderFragment ongoingOrderFragment;

    private FragmentPagerAdapter myOrderAdapter;

    private List<Fragment> listFragment;

    private List<String> titlFragment;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_send_my_orders;
    }

    @Override
    protected void initView(View view) {
        init();

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    private void init() {
        mTvGenericTitle.setText(getActivity().getResources().getString(R.string.my_order_title));
        ongoingOrderFragment = new SendOngoingOrderFragment();
        sendHistoryOrderFragment = new SendHistoryOrderFragment();


        listFragment = new ArrayList<>();
        listFragment.add(ongoingOrderFragment);
        listFragment.add(sendHistoryOrderFragment);

        titlFragment = new ArrayList<>();
        titlFragment.add(getActivity().getResources().getString(R.string.my_order_ongoing));
        titlFragment.add(getActivity().getResources().getString(R.string.my_order_history));

        mTabMeyorderTop.setTabMode(TabLayout.MODE_FIXED);

        mTabMeyorderTop.addTab(mTabMeyorderTop.newTab().setText(titlFragment.get(0)));
        mTabMeyorderTop.addTab(mTabMeyorderTop.newTab().setText(titlFragment.get(1)));

        myOrderAdapter = new GenericViewPagerAdapter(getActivity().getSupportFragmentManager(), listFragment, titlFragment);
        mVpMyorderPager.setAdapter(myOrderAdapter);
        mTabMeyorderTop.setupWithViewPager(mVpMyorderPager);


    }
}
